<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp"%>
<!DOCTYPE html>
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link href="${ctx}/static/css/plugins/jsTree/default/style.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
	<div class="wrapper wrapper-content">
		<div class="row">
			<div class="col-sm-12">

				<div class="ibox float-e-margins">
					<div class="ibox-content">
						<form class="form-horizontal m-t" id="permissionsForm">
							<input type="hidden" name="id" value="${info.id}">
							<div class="form-group">
								<label class="col-sm-3 control-label">权限名称：</label>
								<div class="col-sm-8">
									<input type="text" id="permissionName" class="form-control" name="permissionName" value="${info.permissionName }">
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">备注：</label>
								<div class="col-sm-8">
									<textarea class="form-control" name="remarks">${info.remarks } </textarea>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">功能：</label>
								<div class="col-sm-8">
									<ul id="menuTree"></ul>
								</div>
							</div>
							<div class="form-group">
								<label class="col-sm-3 control-label">状态：</label>
								<div class="col-sm-8">
									<div class="switch">
										<div class="onoffswitch">
											<input type="checkbox" name="status" <c:if test="${info.status eq '1' }"> checked</c:if> class="onoffswitch-checkbox" id="status">
											<label class="onoffswitch-label" for="status"> <span class="onoffswitch-inner"></span> <span class="onoffswitch-switch"></span>
											</label>
										</div>
									</div>
								</div>
							</div>
							<c:if test="${readOnly }">
								<div class="form-group">
									<label class="col-sm-3 control-label">创建人：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" value="${info.createByUserName }">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">创建时间：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" value="${fns:getFormatDateTime(info.createDate )}">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">修改人：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" value="${info.updateByUserName }">
									</div>
								</div>
								<div class="form-group">
									<label class="col-sm-3 control-label">修改时间：</label>
									<div class="col-sm-8">
										<input type="text" class="form-control" value=" ${fns:getFormatDateTime(info.updateDate )}">
									</div>
								</div>
							</c:if>
							<div class="form-group">
								<div class="col-sm-4 col-sm-offset-2">
									<c:if test="${!readOnly   }">
										<shiro:hasPermission name="permissions_update">
											<button class="btn btn-primary" type="submit">保存内容</button>
										</shiro:hasPermission>
									</c:if>
								</div>
							</div>
						</form>
						<div align="center">
							<button class="btn btn-outline btn-danger" type="" id="closeIframe">关闭</button>
						</div>
					</div>
				</div>

			</div>
		</div>
	</div>
	<script src="${ctx}/static/js/plugins/jsTree/jstree.min.js"></script>
	<script type="text/javascript">
		$('#closeIframe').click(function() {
			closeParentWindow();
		});
		var options = {
			elem : '#menuTree', //指定元素，生成的树放到哪个元素上
			check : 'checkbox', //勾选风格
			skin : 'as', //设定皮肤
			url : "",
			drag : true,//点击每一项时是否生成提示信息
			checkboxName : 'menu',//复选框的name属性值
			checkboxStyle : "",//设置复选框的样式，必须为字符串，css样式怎么写就怎么写

		};

		$().ready(function() {
			$.post("${ctx}/menu/treeMenuPermList?permId=${info.id}", {}, function(data) {
				options.nodes = data;
				layui.use([ 'tree' ], function() {
					layui.tree(options)
				});

			}, 'json');
			var e = "<i class='fa fa-times-circle'></i> ";
			$("#permissionsForm").validate({
				rules : {
					permissionName : {
						required : true,
						maxlength : 40
					},
					remarks : {
						maxlength : 255
					}
				},
				messages : {
					permissionName : e + "${fns:getErrorMessage('ERROR_PERMISSION_NAME')}",
					remarks : e + "${fns:getErrorMessage('ERROR_REMARKS')}",
				},
				submitHandler : function(form) {
					var data = formToJson("permissionsForm");
					var menus = "";
					$("input[name='menu']:checkbox:checked").each(function(index, e) {
						menus += this.value + ",";
					});
					if (menus == "") {
						sighMsg("请选择菜单功能！");
						return false;
					}
					data.status = "on" == data.status ? "1" : "0";
					data.menuIds = menus;
					$.post(basePath + "/permissions/save", data, function(data) {
						if (data.success) {
							succuceMsg(data.msg);
							parent.$("#queryTable").bootstrapTable('refresh');
							delayCloseParentWindow();
						} else {
							errorMsg(data.msg);
						}
					}, "json");
				}
			});
		});
	</script>
</body>
</html>